package com.yulongtian.oneProblemEveryDay.month202211.day20221126;

import java.util.HashMap;

/**
 * https://leetcode.cn/problems/maximum-number-of-balls-in-a-box/
 * 可
 *
 * @author yulongTian
 * @create 2022-11-26 14:34
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println(countBalls(8, 16));
    }


    public static int countBalls(int lowLimit, int highLimit) {
        int res = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = lowLimit; i <= highLimit; i++) {
            int temp = getSum(i);
            //包含
            if (map.containsKey(temp)) {
                int i1 = map.get(temp) + 1;
                res = Math.max(res, i1);
                map.put(temp, i1);
            } else {
                map.put(temp, 1);
                res = Math.max(res, 1);
            }
        }

        return res;
    }


    //返回整数的各个位之和
    public static int getSum(int num) {
        int res = 0;
        while (num > 0) {
            res += num % 10;
            num /= 10;
        }
        return res;
    }


}
